package com.example.max.android_test;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends AppCompatActivity {

    private static native void aesTest();

    static {
        System.loadLibrary("lkt");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        new Thread(new Runnable() {
            @Override
            public void run() {
                aesTest();
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep (5000);
                    System.out.println("----------------");


                    // 获取Socket 套接字，指定发送地址以及端口，发送请求
                    // 提示：代表本地客户端地址：10.0.2.2
                    Socket socket = new Socket("192.168.10.51", 55056);
                    System.out.println("==================");

                    // 发送请求数据
                    OutputStream os = socket.getOutputStream();
                    os.write("hello,guojianchuan".getBytes("utf-8"));
                    System.out.println("+++++++++++++");

                    // 获取服务器返回的数据
                    //BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                    //Log.i("msg", "服务器数据："+br.readLine());

                    os.close();
                    //br.close();
                    socket.close();

                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
        }).start();



    }



}
